package Day10_Ex1_arrayList;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

/**
 * @author Mark
 */
public class CollectionTest
{

    public static void main(String[] args)
    {
        String[] colours =
        {
            "MAGENTA", "RED", "WHITE", "BLUE", "CYAN"
        };
        
        List<String> list = new ArrayList<String>();

        for (String colour : colours)
        {
            list.add(colour);
        }

        String[] removeColours =
        {
            "RED", "WHITE", "BLUE"
        };

        List<String> removeList = new ArrayList<String>();

        for (String colour : removeColours)
        {
            removeList.add(colour);
        }

        System.out.println("ArrayList: ");

        for (int count = 0; count < list.size(); count++)
        {
            System.out.printf("%s ", list.get(count));
        }

        
        //Iterator version
        System.out.println("\nIterator ArrayList Output");
        
        @SuppressWarnings("rawtypes")
		Iterator ait = list.iterator();
        for (String string : list)
        {
            System.out.print(ait.next().toString() + " ");
        }
        
        
        removeColours(list, removeList);

        System.out.println("\n\nArrayList after calling removeColours: ");

        for (String colour : list)
        {
            System.out.printf("%s ", colour);
        }
    }

    private static void removeColours(Collection<String> collection1, Collection<String> collection2)
    {
        Iterator<String> iterator = collection1.iterator();

        while (iterator.hasNext())
        {
            if (collection2.contains(iterator.next()))
            {
                iterator.remove();
            }
        }
    }
}
